package com.zpxt.zpxt.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zpxt.zpxt.entity.Company;
import com.zpxt.zpxt.entity.Talent;
import com.zpxt.zpxt.serve.RegisterServe;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:hjx
 * @Description:注册模块
 * @Date: Created in 16:31 2018/4/3
 * @Modified By:
 */
@CrossOrigin
@RestController
public class RegisterController {
    @Resource(name="registerServe")
    RegisterServe registerServe;
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

    @RequestMapping("/hello1")
    public String hello1() {
        return "Hello World";
    }

    @RequestMapping("/addCompany")
    @ResponseBody
    public String addCompany(HttpServletRequest request, HttpServletResponse response) throws Exception {

        String info = request.getParameter("data");
        Company company=gson.fromJson(info, Company.class);

        //添加企业信息
       registerServe.addCompany(company);

        //返回结果
        return gson.toJson("OK");
    }

    @RequestMapping("/addTalent")
    @ResponseBody
    public String addTalent(HttpServletRequest request, HttpServletResponse response) throws Exception {

        String info = request.getParameter("data");
        Talent talent=gson.fromJson(info, Talent.class);

        //添加个人信息
        registerServe.addTalent(talent);

        //返回结果
        return gson.toJson("OK");
    }
}
